<template>
  <div>
    <!-- 遮罩层，点击遮罩层隐藏计算器 -->
    <div class="mask" @click="$emit('hideCalc')"></div>
    <div :style="{ top: top + 'px', left: left + 'px' }" class="calculator">
      <div class="showPanel">
        <span class="exp">{{ exp }}</span>
        <span class="number">{{ number }}</span>
      </div>
      <div class="caculator-button">
        <el-button @keydown="c">c</el-button>
        <el-button @click="getResult('/')">/</el-button>
        <el-button @click="getResult('*')">*</el-button>
        <el-button @click="getResult('del')" icon="delete"> </el-button>

        <el-button @click="getResult('7')">7</el-button>
        <el-button @click="getResult('8')">8</el-button>
        <el-button @click="getResult('9')">9</el-button>
        <el-button @click="getResult('-')">-</el-button>

        <el-button @keydown="48">4</el-button>
        <el-button @click="getResult('5')">5</el-button>
        <el-button @click="getResult('6')">6</el-button>
        <el-button @click="getResult('+')">+</el-button>

        <el-button @click="getResult('1')">1</el-button>
        <el-button @click="getResult('2')">2</el-button>
        <el-button @click="getResult('3')">3</el-button>
        <el-button @click="getResult('=')" type="primary" class="equal">=</el-button>

        <el-button @click="getResult('+/-')">+/-</el-button>
        <el-button @click="getResult('0')">0</el-button>
        <el-button @click="getResult('.')">.</el-button>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'calculator',

}
</script>

<style lang="scss" scoped>
.mask {
  position: absolute;
  z-index: 80;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

.calculator {
  position: fixed;
  z-index: 99;
  border: solid 1px #dcdfe6;
  padding: 5px;
  background-color: #fffffff1;
  border-radius: 4px;
  box-shadow: 0 0 2px #dcdfe6;

  .showPanel {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 2px 20px;
    height: 42px;
    border: 1px #f0f0f0 solid;
    width: 203px;
    border-radius: 4px;
    box-sizing: border-box;
    margin-bottom: 3px;
    justify-content: space-evenly;

    .exp {
      color: #aaa;
      font-size: 10px;
      height: 12px;
    }

    .number {
      font-size: 16px;
      font-weight: 900;
    }
  }

}

.el-button {
  margin: 0 !important;
  padding: 10px;
  font-weight: 600;
  width: 100%;
}

.caculator-button {
  margin: 0 auto;
  width: 190px;
  display: grid;
  border: solid 1px #eee;
  padding: 6px;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 3px;
  border-radius: 4px;
  background-color: #fffffff1;
}

#result {
  margin-bottom: 6px;
}

.equal {
  grid-column: 4/5;
  grid-row: 4/6;
}
</style>